package com.homegoods.orderinfodetail.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;

import com.homegoods.orderinfodetail.R;
import com.homegoods.orderinfodetail.databinding.InfoFragmentItemInfoWebBinding;
import com.kedll.library.fragment.KBaseFragment;
import com.kedll.library.mvp.BasePresenter;
import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;


/**
 * 图文详情webview的Fragment
 */
public class GoodsInfoWebFragment extends KBaseFragment<InfoFragmentItemInfoWebBinding, BasePresenter> {
    public WebView wvDetail;
    private WebSettings websettings;


    @Override
    protected void init() {
        super.init();
        wvDetail = mBinding.wvDetail;
    }

    @Override
    protected void initEvent(Bundle savedInstanceState) {
        String url = "http://m.okhqb.com/item/description/1000334264.html?fromApp=true";
        if (getArguments() != null) {
            url = getArguments().getString("url");
        }
        wvDetail.setFocusable(false);
        wvDetail.loadUrl(url);
        websettings = wvDetail.getSettings();
        websettings.setLoadWithOverviewMode(true);
        websettings.setBuiltInZoomControls(true);
        websettings.setLoadsImagesAutomatically(true);
        websettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        websettings.setBlockNetworkImage(true);
        websettings.setUseWideViewPort(true);
        websettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        wvDetail.setWebViewClient(new GoodsDetailWebViewClient());
    }


    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.info_fragment_item_info_web;
    }

    private class GoodsDetailWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            websettings.setBlockNetworkImage(false);
        }
    }
}
